<template>
  <div id="app">
    <login v-show="loginVisible" v-on:admin="loginAdmin" v-on:success="loginSuccess"></login>
    <user-info v-show="userVisible"></user-info>
  </div>
</template>

<script>
import login from './components/login'
import userInfo from './components/user-info'

export default {
  name: 'app',
  data () {
    return {
      loginVisible: false,
      userVisible: false,
      bookUrl: '/index.html'
    }
  },
  /**
   * 判断cookie中是否有 token 值,如果有跳转到book,没则打开登录
   */
  mounted () {
    if (this.$cookie.get('token')) {
      console.log('access')
      location.href = this.bookUrl
    } else {
      this.loginVisible = true
    }
  },
  methods: {
    loginSuccess () {
      location.href = this.bookUrl
    },
    loginAdmin () {
      this.loginVisible = false
      this.userVisible = true
    }
  },
  components: {
    login, userInfo
  }
}
</script>